﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Drawing.Imaging;
using WeifenLuo.WinFormsUI.Docking;

namespace GraphicsEditor
{
    public partial class FormMainWindow : Form
    {
        public DockPanel dockPanel;
        public string filePathAndName;
        public Stack<Bitmap> undoOptions;


        public FormMainWindow()
        {
            InitializeComponent();

            dockPanel = new DockPanel();
            dockPanel.Dock = DockStyle.Fill;
            dockPanel.BackColor = Color.Gray;
            dockPanel.DockLeftPortion = 100;
            dockPanel.DockRightPortion = 100;
            Controls.Add(dockPanel);
            dockPanel.BringToFront();

            DockContent toolbox = new ToolBox();
            toolbox.Show(dockPanel);
            //toolbox.DockHandler.Pane.MaximumSize = new System.Drawing.Size(100, 999999);

            undoOptions = new Stack<Bitmap>();
        }

        private void loadToolStripMenuItem_Click(object sender, EventArgs e)
        {
            /* This method of loading can support
             *     BMP,GIF,JPEG,PNG and TIFF
             */

            OpenFileDialog openFile = new OpenFileDialog();
            //This should probably be narrowed down/changed as options/files are added, this is just an example for now
            openFile.Filter = "Image Files(*.BMP;*.JPG;*.GIF;*.PNG;*.TIFF)|*.BMP;*.JPG;*.GIF;*.PNG;*.TIFF|All files (*.*)|*.*";

            //use multiselect to open multiple files in the window
            openFile.Multiselect = true;
            if (openFile.ShowDialog() == DialogResult.OK)
            {
                foreach (var file in openFile.FileNames)
                {
                    DockContent content = new ImageForm(file);
                    //content.MdiParent = this;
                    content.Show(dockPanel, DockState.Document);
                }
            }
        }


        /*
         *  Testing this code out, I used it in my data vis class
         * 
         *       
         */
        public static Bitmap SetImageOpacity(Bitmap image, float opacity)
        {
            try
            {
                //create a Bitmap the size of the image provided 
                Bitmap bmp = new Bitmap(image.Width, image.Height);

                //create a graphics object from the image 
                using (Graphics gfx = Graphics.FromImage(bmp))
                {

                    //create a color matrix object 
                    ColorMatrix matrix = new ColorMatrix();

                    //set the opacity 
                    matrix.Matrix33 = opacity;

                    //create image attributes 
                    ImageAttributes attributes = new ImageAttributes();

                    //set the color(opacity) of the image 
                    attributes.SetColorMatrix(matrix, ColorMatrixFlag.Default, ColorAdjustType.Bitmap);

                    //now draw the image 
                    gfx.DrawImage(image, new Rectangle(0, 0, bmp.Width, bmp.Height), 0, 0, image.Width, image.Height, GraphicsUnit.Pixel, attributes);
                }
                return bmp;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                return null;
            }
        }




        private void newToolStripMenuItem_Click(object sender, EventArgs e)
        {
            String newImage = "newImage";
            DockContent content = new ImageForm(newImage);
            content.MdiParent = this;
            content.Show(dockPanel, DockState.Document);

        }

        private void exitToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Close();
        }

        private void aboutToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            MessageBox.Show("Graphics Editor for Capstone project.", "About Box");
        }


    }
}
